package com.longrise.android.byjk.plugins.tabfirst.revision.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.android.byjk.model.Interlocution;
import com.longrise.android.byjk.widget.recyclerviewadapter.SimpleArrayAdapter;


/**
 * Created by sujizhong on 2017/2/21.
 */

public class InterlocutionAdapter extends SimpleArrayAdapter<Interlocution> {

    private LayoutInflater mInflater;
    private boolean mHasFooter = true;

    public InterlocutionAdapter(BaseActivity activity) {
        mInflater = LayoutInflater.from(activity);
    }

    @Override
    protected BaseRecyclerViewHolder onCreateFooterItemViewHolder(ViewGroup parent) {
        return new FooterView(mInflater.inflate(R.layout.footerview, parent, false));
    }

    @Override
    protected BaseRecyclerViewHolder onCreateContentItemViewHolder(ViewGroup parent, int viewType) {
        return new InterlocutionViewHolder(mInflater.inflate(R.layout.item_interlocution, parent, false));
    }

    @Override
    protected void onBindContentView(BaseRecyclerViewHolder holder, int position) {
        parseData((InterlocutionViewHolder) holder, position, getItem(position));
    }

    private void parseData(InterlocutionViewHolder viewHolder, final int position, final Interlocution item) {
        viewHolder.mTextTitle.setText(item.title);
        viewHolder.mTextNick.setText(item.nickname);
        viewHolder.mTextTime.setText(item.createtimestr);
        viewHolder.mTextComment.setVisibility(TextUtils.isEmpty(item.qadesc) ? View.GONE : View.VISIBLE);
        viewHolder.mTextComment.setText(item.qadesc);
        viewHolder.mTextComCount.setText(item.aswnum + "回答");
        viewHolder.mRootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener(position, item);
            }
        });
    }

    @Override
    protected int getContentItemViewType(int position) {
        return 0;
    }

    private class InterlocutionViewHolder extends BaseRecyclerViewHolder {

        private TextView mTextTitle;
        private TextView mTextNick;
        private TextView mTextTime;
        private TextView mTextComment;
        private TextView mTextComCount;
        private View mRootView;

        public InterlocutionViewHolder(View itemView) {
            super(itemView);
            mRootView = itemView;
            mTextTitle = (TextView) itemView.findViewById(R.id.tvtitle_interl);
            mTextNick = (TextView) itemView.findViewById(R.id.tvnick_interl);
            mTextTime = (TextView) itemView.findViewById(R.id.tvtime_interl);
            mTextComment = (TextView) itemView.findViewById(R.id.tvcomment_interl);
            mTextComCount = (TextView) itemView.findViewById(R.id.tvcomcount_interl);
        }
    }

    private class FooterView extends BaseRecyclerViewHolder {

        public FooterView(View itemView) {
            super(itemView);
        }
    }

    public void onItemClickListener(int position, Interlocution item) {

    }

    @Override
    protected boolean hasFooter() {
        return false;
    }

}
